package com.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
//@ApiModel(value="全局数据返回对象", description="DataResult对象")
public class DataResult {
    //@ApiModelProperty(value = "返回状态码")
    private String status;
    //@ApiModelProperty(value = "返回码")
    private Integer code;
    //@ApiModelProperty(value = "返回消息")
    private String message;
    //@ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();
    private DataResult(){}
    public static DataResult finished(){
        DataResult r = new DataResult();
        r.setStatus("finished");
        r.setCode(ResultCode.SUCCESS);
        r.setMessage("请求成功！");
        return r;
    }
    public static DataResult failed(){
        DataResult r = new DataResult();
        r.setStatus("failed");
        r.setCode(ResultCode.ERROR);
        r.setMessage("请求失败！");
        return r;
    }
    public static DataResult untoken(){
        DataResult r = new DataResult();
        r.setStatus("untoken");
        r.setMessage("请检查token是否有效或是否过期！token过期时间：10min");
        return r;
    }
    public DataResult message(String message){
        this.setMessage(message);
        return this;
    }

    public DataResult data(String key, Object value){
        this.data.put(key, value);
        return this;
    }
    public DataResult data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
    public DataResult code(Integer code){
        this.setCode(code);
        return this;
    }
}
